package com.wanbatv.wanba.jianshencao.util;

import android.content.Context;
import android.util.Log;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.wanbatv.wanba.jianshencao.utils.Product;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 俞亚楠 on 2016/3/18.
 */
public class DataReport {
    public static String dev="http://121.201.7.173:28060";
    public static String zhengshi="http://121.201.14.248:28060";
    public static String anhui="http://61.191.46.215:8061";
    public static String url_qian=anhui;
    private static RequestQueue mRq = null;

    private static RequestQueue getRequestQueue(Context context) {
        if (mRq == null) {
            mRq = Volley.newRequestQueue(context);
        }
        return mRq;
    }

    /**
    * 记录程序进入退出接口
    */
    public static void AppRetreat(final Context context,final String actioncode){
        RequestQueue requestQueue = getRequestQueue(context);
        String url=url_qian+"/app";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.e("ceshijinru",response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("appversion", Product.versionName);
                map.put("stbid",Util.getDeviceId(context));
                map.put("stbmodule",android.os.Build.MODEL);
                map.put("platform","android");
                map.put("biz","IPTV");
                map.put("flavor",Product.flavor);
                map.put("userid",AppUtil.STB.UserID);
                map.put("sdkversion",android.os.Build.VERSION.RELEASE);
                map.put("actioncode",actioncode);
                map.put("app",Product.appId);
                map.put("package", context.getPackageName());

                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    /**
     * 记录程序页面进入或退出接口
     */
    public static void PageRetreat(final Context context,final String actioncode,
                                   final String pagecode){
        RequestQueue requestQueue = getRequestQueue(context);
        String url=url_qian+"/page";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("appversion",Product.versionName);
                map.put("stbid",Util.getDeviceId(context));
                map.put("stbmodule",android.os.Build.MODEL);
                map.put("platform","android");
                map.put("biz","IPTV");
                map.put("flavor",Product.flavor);
                map.put("userid",AppUtil.STB.UserID);
                map.put("sdkversion",android.os.Build.VERSION.RELEASE);
                map.put("actioncode",actioncode);
                map.put("package", context.getPackageName());
                map.put("pagecode",pagecode);



                return map;
            }
        };
        requestQueue.add(stringRequest);
    }
    /**
     * 记录内容信息接口
     */
    public static void ContentInformation(final Context context,final String actioncode,
                                          final String categorycode,
                                          final String contentcode,final String contentname,final String duration ){
        RequestQueue requestQueue = getRequestQueue(context);
        String url=url_qian+"/content";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("appversion",Product.versionName);
                map.put("stbid",Util.getDeviceId(context));
                map.put("stbmodule",android.os.Build.MODEL);
                map.put("platform","android");
                map.put("biz","IPTV");
                map.put("flavor",Product.flavor);
                map.put("userid",AppUtil.STB.UserID);
                map.put("sdkversion",android.os.Build.VERSION.RELEASE);
                map.put("actioncode",actioncode);
                map.put("package", context.getPackageName());
                map.put("categorycode",categorycode);
                map.put("contentcode",contentcode);
                map.put("contentname",contentname);
                map.put("duration",duration);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }

    /**
     * 记录内容事件接口
     */
    public static void EventInformation(final Context context,final String actioncode,
                                          final String eventcode,final String eventdata){
        RequestQueue requestQueue = getRequestQueue(context);
        String url=url_qian+"/event";
        StringRequest stringRequest = new StringRequest(com.android.volley.Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
                map.put("appversion",Product.versionName);
                map.put("stbid",Util.getDeviceId(context));
                map.put("stbmodule",android.os.Build.MODEL);
                map.put("platform","android");
                map.put("biz","IPTV");
                map.put("flavor",Product.flavor);
                map.put("userid",AppUtil.STB.UserID);
                map.put("sdkversion",android.os.Build.VERSION.RELEASE);
                map.put("actioncode",actioncode);
                map.put("package", context.getPackageName());
                map.put("eventcode",eventcode);
                map.put("eventdata",eventdata);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }
}
